package com.shujia.mllib

import org.apache.spark.ml.classification.LogisticRegressionModel
import org.apache.spark.ml.linalg
import org.apache.spark.ml.linalg.Vectors
import org.apache.spark.sql.SparkSession

object Demo3ModelUse {
  def main(args: Array[String]): Unit = {


    val spark: SparkSession = SparkSession.builder()
      .appName("person")
      .master("local")
      .config("spark.sql.shuffle.partitions", "2")
      .getOrCreate()

    import spark.implicits._
    import org.apache.spark.sql.functions._


    /**
      *
      * 模型使用
      *
      */

    //1、加载hdfs模型
    val model: LogisticRegressionModel = LogisticRegressionModel.load("spark/data/model")


    /**
      *
      * 新的数据
      * 1:5.3 2:3.5 3:2.5 4:106.4 5:67.5 6:69.1 7:83
      *
      * 1 1:5.9 2:3.9 3:3.0 4:135.0 5:82.8 6:79.5 7:64
      *
      */

    val vector: linalg.Vector = Vectors.dense(Array(5.3, 3.5, 2.5, 106.4, 67.5, 69.1, 83))

    //2、预测
    val d: Double = model.predict(vector)

    println(d)


    val vector1: linalg.Vector = Vectors.dense(Array(5.9, 3.9, 3.0, 135, 82.8, 79.5, 64))
    val d1: Double = model.predict(vector1)
    println(d1)

  }

}
